package com.coustemview.qianfeng.huaqiangbeistore.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import com.coustemview.qianfeng.huaqiangbeistore.R;
import com.coustemview.qianfeng.huaqiangbeistore.application.Myapplication;
import com.coustemview.qianfeng.huaqiangbeistore.config.Netconfig;
import com.coustemview.qianfeng.huaqiangbeistore.model.Oversear_specialcation_Bean;
import com.google.gson.Gson;

import org.xutils.common.Callback;
import org.xutils.http.RequestParams;
import org.xutils.x;

import java.util.List;

/**
 * Created by mingma on 2016/9/1.
 */
public class Fragment_oversear_shopdetails2 extends Fragment {
   private TextView  text_oversear_shopname1,text_oversear_shopname2,text_oversear_shopname3,text_oversear_shopname4,text_oversear_shopname5,text_oversear_shopname6,text_oversear_shopname7,text_oversear_shopname8,text_oversear_shopname9,text_oversear_shopname10;
   private TextView text_oversear_shopnumber1,text_oversear_shopnumber2,text_oversear_shopnumber3,text_oversear_shopnumber4,text_oversear_shopnumber5,text_oversear_shopnumber6,text_oversear_shopnumber7,text_oversear_shopnumber8,text_oversear_shopnumber9,text_oversear_shopnumber10;
    private Myapplication application;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_oversear_shopdetails2, null);
        initView(view);
        initData();
        return view;
    }

    private void initData() {
        application = (Myapplication) getActivity().getApplication();
        String skuid = application.getSkuid();
         int id = Integer.parseInt(skuid);
         String path = String.format(Netconfig.SPECIAL_CATION_PATH, id);
        RequestParams params=new RequestParams(path);
        x.http().get(params, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
               if(result!=null) {
                   Gson mGson=new Gson();
                   Oversear_specialcation_Bean specialcationBean = mGson.fromJson(result, Oversear_specialcation_Bean.class);
                   List<Oversear_specialcation_Bean.DataBean> data = specialcationBean.getData();
                   for (int i = 0; i <data.size() ; i++) {
                         if(i==0) {
                             Oversear_specialcation_Bean.DataBean bean = data.get(0);
                             String keyProp = bean.getKeyProp();
                              text_oversear_shopname1.setText(keyProp);
                             String value = bean.getValue();
                             text_oversear_shopnumber1.setText(value);
                         }else if(i==1) {
                             Oversear_specialcation_Bean.DataBean bean = data.get(1);
                             String keyProp = bean.getKeyProp();
                             text_oversear_shopname2.setText(keyProp);
                             String value = bean.getValue();
                             text_oversear_shopnumber2.setText(value);
                         }else if(i==2) {
                             Oversear_specialcation_Bean.DataBean bean = data.get(2);
                             String keyProp = bean.getKeyProp();
                             text_oversear_shopname3.setText(keyProp);
                             String value = bean.getValue();
                             text_oversear_shopnumber3.setText(value);
                         }else if(i==3) {
                             Oversear_specialcation_Bean.DataBean bean = data.get(3);
                             String keyProp = bean.getKeyProp();
                             text_oversear_shopname4.setText(keyProp);
                             String value = bean.getValue();
                             text_oversear_shopnumber4.setText(value);
                         }else if(i==4) {
                             Oversear_specialcation_Bean.DataBean bean = data.get(4);
                             String keyProp = bean.getKeyProp();
                             text_oversear_shopname5.setText(keyProp);
                             String value = bean.getValue();
                             text_oversear_shopnumber5.setText(value);
                         }else if(i==5) {
                             Oversear_specialcation_Bean.DataBean bean = data.get(5);
                             String keyProp = bean.getKeyProp();
                             text_oversear_shopname6.setText(keyProp);
                             String value = bean.getValue();
                             text_oversear_shopnumber6.setText(value);
                         }else if(i==6) {
                             Oversear_specialcation_Bean.DataBean bean = data.get(6);
                             String keyProp = bean.getKeyProp();
                             text_oversear_shopname7.setText(keyProp);
                             String value = bean.getValue();
                             text_oversear_shopnumber7.setText(value);
                         }else if(i==7) {
                             Oversear_specialcation_Bean.DataBean bean = data.get(7);
                             String keyProp = bean.getKeyProp();
                             text_oversear_shopname8.setText(keyProp);
                             String value = bean.getValue();
                             text_oversear_shopnumber8.setText(value);
                         }else if(i==8) {
                             Oversear_specialcation_Bean.DataBean bean = data.get(8);
                             String keyProp = bean.getKeyProp();
                             text_oversear_shopname9.setText(keyProp);
                             String value = bean.getValue();
                             text_oversear_shopnumber9.setText(value);
                         }else if(i==9) {
                             Oversear_specialcation_Bean.DataBean bean = data.get(9);
                             String keyProp = bean.getKeyProp();
                             text_oversear_shopname10.setText(keyProp);
                             String value = bean.getValue();
                             text_oversear_shopnumber10.setText(value);
                         }
                   }
               }
            }
            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
           Toast.makeText(getActivity(), "网络出错,请检查网络", Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onCancelled(CancelledException cex) {

            }

            @Override
            public void onFinished() {

            }
        });
    }

    private void initView(View view) {
        text_oversear_shopname1= (TextView) view.findViewById(R.id.text_oversear_shopname1);
        text_oversear_shopname2= (TextView) view.findViewById(R.id.text_oversear_shopname2);
        text_oversear_shopname3= (TextView) view.findViewById(R.id.text_oversear_shopname3);
        text_oversear_shopname4= (TextView) view.findViewById(R.id.text_oversear_shopname4);
        text_oversear_shopname5= (TextView) view.findViewById(R.id.text_oversear_shopname5);
        text_oversear_shopname6= (TextView) view.findViewById(R.id.text_oversear_shopname6);
        text_oversear_shopname7= (TextView) view.findViewById(R.id.text_oversear_shopname7);
        text_oversear_shopname8= (TextView) view.findViewById(R.id.text_oversear_shopname8);
        text_oversear_shopname9= (TextView) view.findViewById(R.id.text_oversear_shopname9);
        text_oversear_shopname10= (TextView) view.findViewById(R.id.text_oversear_shopname10);
        text_oversear_shopnumber1= (TextView) view.findViewById(R.id.text_oversear_shopnumber1);
        text_oversear_shopnumber2= (TextView) view.findViewById(R.id.text_oversear_shopnumber2);
        text_oversear_shopnumber3= (TextView) view.findViewById(R.id.text_oversear_shopnumber3);
        text_oversear_shopnumber4= (TextView) view.findViewById(R.id.text_oversear_shopnumber4);
        text_oversear_shopnumber5= (TextView) view.findViewById(R.id.text_oversear_shopnumber5);
        text_oversear_shopnumber6= (TextView) view.findViewById(R.id.text_oversear_shopnumber6);
        text_oversear_shopnumber7= (TextView) view.findViewById(R.id.text_oversear_shopnumber7);
        text_oversear_shopnumber8= (TextView) view.findViewById(R.id.text_oversear_shopnumber8);
        text_oversear_shopnumber9= (TextView) view.findViewById(R.id.text_oversear_shopnumber9);
        text_oversear_shopnumber10= (TextView) view.findViewById(R.id.text_oversear_shopnumber10);
    }
}
